百度这些东西,还是会浪费了一些不必要的时间,记录记录以备后续
一、开启伪静态
如果不在web.config中配置管道开关则伪静态无效
首先在RouteConfig.cs中中注册路由
1
2
3
4
5routes.MapRoute(
name: "index",
url: "index.html",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);在web.config中的system.webServer节点添加配置项
1
2
3<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
二、使用Bundle压缩css,js
- 添加Nuget包
Microsoft.AspNet.Web.Optimization
- 配置BundleConfig.cs文件
1 | public class BundleConfig |
- 在Global.asax的Application_Start()中注册配置
BundleConfig.RegisterBundles(BundleTable.Bundles);
- 需要注意的地方
- StyleBundle构造函数中的路径为虚拟路径,即不用关心目录是否存在
- 若web.config中配置了
<modules runAllManagedModulesForAllRequests="true" />
,则序StyleBundle传递的虚拟路径可以包含后缀名.css/.js - Bundle压缩合并功能可由web.config中的system.web节点下
<compilation debug="false" targetFramework="4.5" />
的debug值控制,或者在RegisterBundles方法中强制启用:BundleTable.EnableOptimizations = true;
三、layui富文本编辑器中的文件上传接口
1 | public class FileController : Controller |
四、使用js-xss进行xss的防御
- 保存xss.js到本地并在页面中引用
- 使用filterXss(html,options)调用函数处理,根据规则将规则内的html编码
1 | // 使用函数名 filterXSS,用法一样 |
- 实际使用
执行结果对比
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15//定义自己的规则
var myXssOptions = function (isEditer) {
return {
onTagAttr: function (tag, name, value, isWhiteAttr) {
//保留style标签 默认会将style给干掉
if (name == 'style') {
return "style='" + value + "'";
}
//替换src为lay-src做懒加载
if (!isEditer && tag == 'img' && name == 'src') {
return "lay-src='" + value + "'";
}
}
}
};